﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Runtime.InteropServices;
using System.Web.Http;
using UserSystem;

namespace WebTestSample.Controllers
{
    /// <summary>
    /// 认证
    /// </summary>
    public class AuthController : ApiController
    {
        [System.ComponentModel.DataAnnotations.Display]
        private readonly IUserService _userService;

        /// <summary>
        /// ctor
        /// </summary>
        /// <param name="userService"></param>
        public AuthController(IUserService userService)
        {
            _userService = userService;
        }
        /// <summary>
        /// UserLogin
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="password">密码</param>
        /// <returns></returns>
        public int UserLogin(string userName, string password)
        {
            return _userService.UserLogin(userName, password);
        }

        /// <summary>
        /// UserLogin
        /// </summary>
        /// <param name="user">User</param>
        /// <returns>string</returns>
        [HttpPost]
        public string UserLogin([FromBody]User user)
        {
            var id = _userService.UserLogin(user.UserName, user.Password);
            if (id > 0)
            {
                return "登陆成功:" + id;
            }
            else
            {
                return "登陆失败";
            }
        }

        // GET api/<controller>/5
        /// <summary>
        /// Get
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public string Get(int id)
        {

            return "value";
        }
    }
}